#ifndef MAINLOGIC_H
#define MAINLOGIC_H
#include "stm32f4xx_hal.h"
#include "stdio.h"
#include "gps.h"

typedef struct
{
	uint8_t* dmabuf;
	uint8_t* line;
	uint16_t lineStart;
	uint16_t lineEnd;
	uint16_t dmabufLen;
	uint16_t lineLen;
	uint16_t readIdx;
	uint16_t lastCT;
	uint32_t lastTick;
} UartBuf;

typedef struct
{
	uint8_t valid;
	uint8_t timeValid;
	uint16_t year;
	uint8_t month;
	uint8_t day;
	uint8_t hour;
	uint8_t min;
	uint8_t sec;
	double lat;
	double lon;
	uint8_t satCount;
	GpsType type;
	char latDir;
	char lonDir;
} GpsStatus;

typedef struct
{
	float temp;
	float mcuTemp;
	float basetemp;
	double tempCofe;
	double ageCofe;
	double tempCofe24;
	double ageCofe24;
	double avg;
	uint8_t cofeValid;
	uint8_t cofe24Valid;
} ControllerStatus;

#define ADC2PS 64.145f

extern ControllerStatus g_ctlStatus;
extern GpsStatus g_gpsStatus;

void init_user(void);
void user_runloop(void);
void setDacValue(int32_t value, uint8_t offsetModel);
void setDacValueDirect(int32_t high, uint32_t low);
float TimeUpdateRate(void);
void ShowADMinMax(void);

#endif
